package com.heaven.jane.sourcegenerator.commons.security.user.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.heaven.jane.sourcegenerator.commons.security.authority.domain.Authority;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**
	 * 主键id
	 */
	@Id
	@SequenceGenerator(name = "user_generator", sequenceName = "user_sequence", initialValue = 0)
	@GeneratedValue(generator = "user_generator")
	private Long id;
	
	/**
	 * 登录用户名
	 */
	private String username;
	
	/**
	 * 密码
	 */
	private String password;
	
	/**
	 * 角色信息
	 */
	@ManyToMany(cascade = {CascadeType.MERGE})
	@JsonIgnore
	@JoinTable(name = "UserAuthority",
	        joinColumns = { @JoinColumn(name = "userid", referencedColumnName = "id") },
	    inverseJoinColumns = { @JoinColumn(name = "authorityid", referencedColumnName = "id") })
	private Set<Authority> authoritys;

	/**
	 * 登录凭证
	 */
	private String token;

	/**
	 * 描述
	 */
	private String introduction;

	/**
	 * 头像
	 */
	private String avatar;
	
	/**
	 * 姓
	 */
    private String firstname;
    
    /**
     * 名
     */
    private String lastname;
    
    /**
     * 邮箱
     */
    private String email;
    
    /**
     * 启用状态
     */
    private Boolean enabled;
    
    /**
     * 上次密码重置时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastPasswordResetDate;

}
